<!-- File: /app/views/posts/index.ctp -->
<script>

$(function() {
    
    var controllers = new Array();
    controllers['people'] = "<?php echo str_replace('"', '\"', $this->Html->url(array(
                                                        'controller' => 'People',
                                                        'action'    => 'edit'
                                                    ))); ?>";
    controllers['work_experiences'] = "<?php echo str_replace('"', '\"', $this->Html->url(array(
                                                        'controller' => 'WorkExperiences',
                                                        'action'    => 'index'
                                                    ))); ?>";
    controllers['education_experiences'] = "<?php echo str_replace('"', '\"', $this->Html->url(array(
                                                        'controller' => 'EducationExperiences',
                                                        'action'    => 'index'
                                                    ))); ?>";
    controllers['language_experiences'] = "<?php echo str_replace('"', '\"', $this->Html->url(array(
                                                        'controller' => 'LanguageExperiences',
                                                        'action'    => 'index'
                                                    ))); ?>";                                             

    $( '.edit_select' ).change(function() {
        
        var values = this.value.split("-");
        var controller = values[0];
        var user_id = values[1];

        if(controller != 'people')
            window.location.href = controllers[controller]+'/index/'+user_id;
        else
            window.location.href = controllers[controller]+'/'+user_id;

    })

})

</script>
<h1>Curriculum presenti</h1>
<table class="contentTable">
	<tr>
		<th>Nome e cognome</th>
        <th>Visualizza/modifica</th>
<!--		<th>Azioni</th>-->
        <th>Data inserimento</th>
	</tr>

	<!-- Here is where we loop through our $posts array, printing out post info -->
        <!-- la variabile posts l'ho settata nel controller Post -->
	<?php foreach ($people as $person): ?>
	<tr>
		<td>
                <?php
                    echo $person['Person']['name'].' '.$person['Person']['surname'];
                ?>
		</td>
        <td>
            <!-- uses the HtmlHelper to prompt the user with a JavaScript
                 confirmation dialog before they attempt to delete a post. -->
            <select class="edit_select">
                <option value=""></option>
                <option value="people-<?php echo $person['Person']['id'] ?>">Informazioni personali</option>
                <option value="work_experiences-<?php echo $person['Person']['id'] ?>">Esperienze di lavoro</option>
                <option value="education_experiences-<?php echo $person['Person']['id'] ?>">Esperienze di istruzione</option>
                <option value="language_experiences-<?php echo $person['Person']['id'] ?>">Esperienze linguistiche</option>
            </select>
        </td>
<!--        <td>-->
            <?php //echo $html->link('Download Europass XML', 
//                                    array('controller' => 'Curriculums', 'action' => 'download_xml', $person['Person']['id']),
//                                    array('class' => 'button')
//                                  );?>
            <?php //echo $html->link('Elimina', 
//                                    array('action' => 'delete', $person['Person']['id']), 
//                                    array('class' => 'button'), 
//                                    'Sei sicuro di voler eliminare il curriculum selezionato?' 
//                                  )?>

<!--        </td>-->
        <td>
            data
        </td>
	</tr>
	<?php endforeach; ?>

</table>
<div class="footer_buttons">
<?php echo $html->link('Aggiungi un curriculum',
                        array('controller' => 'people', 'action' => 'add'),
                        array('class' => 'button'))?>
</div>
